/** layuiAdmin-v1.2.1  License By  */
("use strict");
function _typeof(t) {
  return (_typeof =
    "function" == typeof Symbol && "symbol" == typeof Symbol.iterator
      ? function (t) {
          return typeof t;
        }
      : function (t) {
          return t &&
            "function" == typeof Symbol &&
            t.constructor === Symbol &&
            t !== Symbol.prototype
            ? "symbol"
            : typeof t;
        })(t);
}
layui.define(["table"], function (t) {
  var r = layui.$,
    d = layui.layer,
    p = layui.laytpl,
    i = layui.setter,
    f = layui.view,
    y = layui.admin,
    g = layui.api,
    e = layui.table,
    v = layui.form;
  t("utill", {
    submit: function (t, e, n, o, i) {
      var a = { done: function (t) {} };
      r.extend(a, i),
        y.req({
          url: g.host + t,
          data: JSON.stringify(e),
          dataType: "json",
          contentType: "application/json",
          type: o || "POST",
          done: function (t) {
            layui.table.reload(n),
              a.done(t),
              d.open({ title: "提示", content: t.message });
          },
        });
    },
    alert: function (t, e, n, o, i, a, l) {
      var u = 6 < arguments.length && void 0 !== l ? l : "submit",
        c = {
          done: function (t) {},
          then: function (t) {},
          click_done: function () {},
        };
      r.extend(c, t),
        r(e).on("click", ".add-btn", function (t) {
          c.click_done(),
            y.popup({
              title: n,
              area: o,
              shadeClose: !1,
              success: function (t, e) {
                f(this.id)
                  .render(i)
                  .done(function (t) {
                    c.then(),
                      r(a).click(function () {
                        d.close(e);
                      }),
                      v.on("submit(".concat(u, ")"), function (t) {
                        c.done(t.field);
                      });
                  });
              },
            });
        });
    },
    myalert: function (t, e, n, o, i, a, l) {
      var u = 6 < arguments.length && void 0 !== l ? l : "submit",
        c = { done: function (t, e) {}, then: function (t) {} };
      r.extend(c, i),
        y.popup({
          title: t,
          area: e,
          shadeClose: !1,
          success: function (t, e) {
            f(this.id)
              .render(n)
              .done(function (t) {
                c.then(a),
                  r(o).click(function () {
                    d.close(e);
                  }),
                  v.on("submit(".concat(u, ")"), function (t) {
                    c.done(t.field, a);
                  });
              });
          },
        });
    },
    keyup: function (t, e, n) {
      n || window.event;
      r(t).bind("keydown", function (t) {
        if ("13" == t.keyCode) return r(e).trigger("click"), !1;
      });
    },
    timestampToTime: function (t) {
      var e = new Date(t);
      return (
        (Y = e.getFullYear() + "-"),
        (M =
          (e.getMonth() + 1 < 10
            ? "0" + (e.getMonth() + 1)
            : e.getMonth() + 1) + "-"),
        (D = (e.getDate() < 10 ? "0" + e.getDate() : e.getDate()) + " "),
        (h = (e.getHours() < 10 ? "0" + e.getHours() : e.getHours()) + ":"),
        (m =
          (e.getMinutes() < 10 ? "0" + e.getMinutes() : e.getMinutes()) + ":"),
        (s = e.getSeconds() < 10 ? "0" + e.getSeconds() : e.getSeconds()),
        Y + M + D + h + m + s
      );
    },
    timeday: function (t) {
      var e = new Date(t);
      return (
        (Y = e.getFullYear() + "-"),
        (M =
          (e.getMonth() + 1 < 10
            ? "0" + (e.getMonth() + 1)
            : e.getMonth() + 1) + "-"),
        (D = e.getDate() < 10 ? "0" + e.getDate() : e.getDate()),
        Y + M + D
      );
    },
    fuzzmatch: function (n, t, e) {
      var i,
        a,
        o = !1,
        l = r('<div class="layui-form-autocomplete"></div>'),
        u = r(
          '<dl id="select_show" name="select_show" class="layui-anim layui-anim-upbit"></dl>'
        ),
        c = {
          reqObj: {
            url: g.host + g.xjjh.planGenQuery + "?planGen=" + r(n).val(),
            type: "POST",
          },
          dataTrans: function (t) {
            t.code;
            return t.data.map(function (t) {
              return { label: t.gen02, value: t.tcHrGen01 };
            });
          },
          done: function (t) {
            t.code, t.data;
          },
          isShowValue: !0,
          click: null,
        };
      function s(t) {
        var n = "",
          o = (t = t).val();
        clearTimeout(a),
          (a = setTimeout(function () {
            i &&
              i.forEach(function (t, e) {
                (-1 < t.value.indexOf(o) || -1 < t.label.indexOf(o)) &&
                  (n += c.isShowValue
                    ? '<dd lay-value="" class="layui-select-tips" data-item=\''
                        .concat(JSON.stringify(t), "'>\n\t\t\t\t\t\t\t\t<span>")
                        .concat(
                          t.label,
                          '</span>\n\t\t\t\t\t\t\t\t<span class="isShowValue">'
                        )
                        .concat(t.value, "</span>\n\t\t\t\t\t\t\t</dd>")
                    : '<dd lay-value="" class="layui-select-tips" data-item=\''
                        .concat(
                          JSON.stringify(t),
                          "'>\n\t\t\t\t\t\t\t\t\t<span>"
                        )
                        .concat(t.label, "</span>\n\t\t\t\t\t\t\t</dd>"));
              }),
              u.html(""),
              u.append(n),
              l.append(u),
              r(".layui-form-autocomplete").remove(),
              t.after(l),
              0 == i.length &&
                r(".layui-form-autocomplete dl").append(
                  '<dd style="text-align: center">未找到</dd>'
                );
          }, 500));
      }
      r.extend(c, t),
        r(n).parent("div").addClass("completeWrap"),
        r("body")
          .off("input propertychange", n)
          .on("input propertychange", n, function (t) {
            s(r(t.target));
          }),
        r("body")
          .off("focus", n)
          .on("focus", n, function (t) {
            var e = r(t.target);
            o
              ? s(e)
              : ((o = !0),
                f.req(c.reqObj).done(function (t) {
                  (o = !1), 0 == t.code && ((i = c.dataTrans(t)), s(e));
                })),
              (function (n) {
                r("body")
                  .off("click", ".layui-form-autocomplete dl dd")
                  .on("click", ".layui-form-autocomplete dl dd", function (t) {
                    var e = r(this);
                    (item = e.data("item")),
                      item &&
                        (r(n).val(item.label),
                        r(n).attr("data-id", item.value),
                        c.click && c.click(item),
                        c.done(item)),
                      r(".layui-form-autocomplete").remove();
                  });
              })(n);
          })
          .off("blur", n)
          .on("blur", n, function (t) {
            setTimeout(function () {
              r(".layui-form-autocomplete").remove();
            }, 200),
              "" == r(n).val() && (r(n).val(""), r(n).attr("data-id", ""));
          });
    },
    loading: {
      elem: r(
        '<i class="layui-anim layui-anim-rotate layui-anim-loop layui-icon layui-icon-loading layadmin-loading"></i>'
      ),
      show: function () {
        this.elem = d.load(2, { time: 1e4 });
      },
      hide: function () {
        this.elem && d.close(this.elem);
      },
    },
    tableOpts: function () {
      var t = layui.sessionData(i.tableName),
        e = i.request.tokenName,
        n = t[e],
        o = {};
      return (
        (o[e] = n),
        {
          loading: !0,
          method: "POST",
          request: { pageName: "pageNum", limitName: "pageSize" },
          page: {
            layout: ["prev", "page", "next", "skip", "count", "limit"],
            limits: [10, 20, 30, 50],
            theme: "#009688",
          },
          parseData: function (t) {
            var e = i.response,
              n = e.statusCode;
            return (
              t[e.statusName] == n.ok ||
                (t[e.statusName] == n.logout
                  ? d.alert(
                      t[e.msgName],
                      { btnAlign: "c", closeBtn: 0 },
                      function (t) {
                        d.close(t), f.exit(), d.closeAll();
                      }
                    )
                  : t[e.statusName] == n.quanxian
                  ? d.alert(
                      t[e.msgName],
                      { btnAlign: "c", closeBtn: 0 },
                      function (t) {
                        d.close(t), d.closeAll();
                      }
                    )
                  : t[e.statusName] == n.loginNone
                  ? d.alert(
                      t[e.msgName],
                      { btnAlign: "c", closeBtn: 0 },
                      function (t) {
                        d.close(t), f.exit(), d.closeAll();
                      }
                    )
                  : d.alert(
                      t[e.msgName],
                      { btnAlign: "c", closeBtn: 0 },
                      function (t) {
                        d.close(t), d.closeAll();
                      }
                    )),
              {
                code: t.code,
                msg: t.message,
                count: t.data.total,
                data: t.data.list,
              }
            );
          },
          contentType: "application/json",
          headers: o,
          cellMinWidth: 120,
        }
      );
    },
    getQueryVariable: function (t) {
      return layui.router().search[t];
    },
    columnTPL: function () {
      return '<form class="layui-form sortList" style="padding: 20px">\n\t\t\t{{# for ( var i = 0; i<= d.columnList.length -1; i++) { }}\n\t\t\t  <div class="layui-form-item">\n\t\t\t\t{{# if ( d.columnList[i].status == 1 ) { }}\n\t\t\t\t  <input type="checkbox" data-status={{ d.columnList[i].status }} value="{{ d.columnList[i].tcEamCustid }}" name="columnCheck" lay-skin="primary" title="{{ d.columnList[i].cname || \'\' }}" checked="">\n\t\t\t\t{{# } else { }}\n\t\t\t\t  <input type="checkbox" data-status={{ d.columnList[i].status }} value="{{ d.columnList[i].tcEamCustid }}" name="columnCheck" lay-skin="primary" title="{{ d.columnList[i].cname || \'\' }}" >\n\t\t\t\t{{# } }}\n\t\t\t  </div>\n\t\t\t{{# } }}\n\t\t\t<button type="button" id="updateColumn" lay-filter="updateColumn" lay-submit style="display: none"></button>\n\t\t  </form>';
    },
    showAndHide: function (e, t) {
      y.req({
        type: "post",
        url: g.host + g.ispermit_zfj,
        data: { prmit: t },
        success: function (t) {
          t.data ? r(e).show() : r(e).hide();
        },
      });
    },
    columnCustom: function (i, a, t) {
      var l = { columnCustom: [] },
        u = this,
        c = {
          toolbar: null,
          templet: null,
          event: null,
          url: null,
          where: null,
          done: null,
          checkbox: !0,
          height: "",
        };
      (c = r.extend({}, c, t)),
        f
          .req({
            url: g.host + g.columnCustom,
            data: JSON.stringify({ tname: a }),
            type: "POST",
            contentType: "application/json",
            cellMinWidth: 120,
            minWidth: 120,
          })
          .done(function (t) {
            var o = [];
            c.checkbox && o.push({ type: "checkbox" }),
              "0" == t.code &&
                ((l.columnCustom = t.data),
                null != c.toolbar && o.push(c.toolbar),
                t.data &&
                  t.data.map(function (t, e) {
                    if ("1" == t.status) {
                      var n = {
                        field: t.ename,
                        title: t.cname,
                        event: "detail",
                        cellMinWidth: 120,
                      };
                      c.templet &&
                        c.templet[t.ename] &&
                        (n.templet = c.templet[t.ename]),
                        c.event &&
                          c.event[t.ename] &&
                          (n.event = c.event[t.ename]),
                        o.push(n);
                    }
                  }),
                o.push({
                  field: "",
                  title: "",
                  width: 10,
                  unresize: !1,
                  cellMinWidth: 120,
                  minWidth: 120,
                })),
              e.render(
                r.extend({}, u.tableOpts(), {
                  elem: i,
                  id: i,
                  height: c.height,
                  url: c.url,
                  where: c.where,
                  defaultToolbar: [],
                  toolbar: c.toolbarh,
                  unresize: !1,
                  cellMinWidth: 120,
                  minWidth: 120,
                  cols: [o],
                  done: function (t, e, n) {
                    r('[lay-id="' + i + '"]').append(
                      '<div class="columnCustomBtn layui-inline" title="筛选列" lay-event><i class="layui-icon layui-icon-cols" style="font-size: 16px;"></i> </div>'
                    ),
                      r('[lay-id="' + i + '"]').css({ position: "relative" }),
                      r('[lay-id="' + i + '"]')
                        .find(".columnCustomBtn")
                        .css({
                          position: "absolute",
                          right: "3px",
                          top: "8px",
                          cursor: "pointer",
                        }),
                      r('[lay-id="' + i + '"]')
                        .find(".columnCustomBtn")
                        .click(function () {
                          d.open({
                            type: 1,
                            title: !1,
                            area: ["268px", "400px"],
                            fixed: !0,
                            shadeClose: !0,
                            closeBtn: 0,
                            btn: ["保存", "取消"],
                            btnAlign: "c",
                            content: p(u.columnTPL()).render({
                              columnList: l.columnCustom,
                            }),
                            success: function (t, e) {
                              r(".sortList").sortable(),
                                r(".sortList").disableSelection(),
                                v.render();
                              var n = {
                                  customGens: [{ customizingId: 0 }],
                                  pattern: 0,
                                },
                                o = !1;
                              v.on("submit(updateColumn)", function (t) {
                                if (
                                  ((n.customGens = []),
                                  r('[name="columnCheck"]').each(function () {
                                    var t = r(this).prop("checked") ? 1 : 0;
                                    n.customGens.push({
                                      customizingId: r(this).val(),
                                      status: t,
                                    });
                                  }),
                                  0 == n.customGens.length)
                                )
                                  return d.msg("至少选择一项"), !1;
                                clearTimeout(o),
                                  (o = setTimeout(function () {
                                    f.req({
                                      url: g.host + g.updateColumn,
                                      type: "POST",
                                      data: JSON.stringify(n),
                                      contentType: "application/json",
                                    }).done(function (t) {
                                      "0" == t.code &&
                                        (d.close(e), u.columnCustom(i, a, c)),
                                        d.msg(t.message);
                                    });
                                  }, 1e3));
                              });
                            },
                            yes: function (t, e) {
                              r("#updateColumn").click();
                            },
                          });
                        }),
                      c.done && c.done(t, e, n);
                  },
                })
              );
          });
    },
    dropdownEvent: function (t) {
      r("body")
        .off("click", ".toggle-btn")
        .on("click", ".toggle-btn", function (t) {
          var e = r(this).siblings(".toggle-content"),
            n = r(this).find(".layui-icon-down");
          e.hasClass("toggle-content-on")
            ? (e.removeClass("toggle-content-on"),
              n.addClass("layui-icon-down").removeClass("layui-icon-up"))
            : (e.addClass("toggle-content-on"),
              n.addClass("layui-icon-up").removeClass("layui-icon-down"));
        });
    },
    setCookie: function (t, e, n) {
      var o = new Date();
      o.setTime(o.getTime() + 24 * n * 60 * 60 * 1e3);
      var i = "expires=" + o.toUTCString();
      document.cookie = t + "=" + e + "; ";
    },
    getCookie: function (t) {
      for (var e = document.cookie.split("; "), n = 0; n < e.length; n++) {
        var o = e[n].split("=");
        if (t == o[0]) return o[1];
      }
      return "";
    },
    deepCopy: function (t) {
      var e = Array.isArray(t) ? [] : {};
      for (var n in t)
        t.hasOwnProperty(n) &&
          (t[n] && "object" === _typeof(t[n])
            ? (e[n] = this.deepCopy(t[n]))
            : (e[n] = t[n]));
      return e;
    },
  });
});
